package com.lbb.waimai.Interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    PermissionVerificationInterceptor interceptor;

    /**
     * 除了登录时不用验证身份，其他接口都要验证身份
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor).addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")

                .excludePathPatterns("/user/login")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/food/**")
                .excludePathPatterns("/seller/**")
                .excludePathPatterns("/category/**")
                .excludePathPatterns("/user/register");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
